package com.jiyongjun.bms.base.configurer;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import javax.servlet.Servlet;

/**
 * <h2>druid数据库连接池配置</h2>
 * description:
 *
 * @author yongjun.ji
 * @since 1.0 2019/5/31
 */
@Configuration
public class DruidConfigurer {

    /**
     * 提供监控信息展示的html页面
     * 提供监控信息的JSON API
     * @return
     */
    @Bean
    public ServletRegistrationBean druidServlet() {
        ServletRegistrationBean<Servlet> servletRegistrationBean = new ServletRegistrationBean<>();
        servletRegistrationBean.setServlet(new StatViewServlet());
        servletRegistrationBean.addUrlMappings("/druid/*");
        servletRegistrationBean.addInitParameter("resetEnable", "false");
        servletRegistrationBean.addInitParameter("allow", "");
        return servletRegistrationBean;
    }

    @Bean
    public DruidStatInterceptor druidStatInterceptor(){
        return new DruidStatInterceptor();
    }

    /*@Bean
    @Scope("prototype")
    public JdkRegexpMethodPointcut jdkRegexpMethodPointcut(){
        JdkRegexpMethodPointcut pointcut=new JdkRegexpMethodPointcut();
        String[] str={"com.len.service.*","com.len.mapper.*"};
        pointcut.setPatterns(str);
        return pointcut;
    }*/
}
